<script src="/assets/backend/ueditor/third-party/codemirror/codemirror.js"></script>
<link rel="stylesheet" href="/assets/backend/ueditor/third-party/codemirror/codemirror.css">
<link rel="stylesheet" href="/assets/backend/ueditor/third-party/codemirror/xq-light.css">

<style>
    #model_showInList_form .textbox-label {
        width: 40px;
        margin-right: 20px;
    }

    .CodeMirror {
        border: 1px solid #eee;
        height: {{.codeEditorHeight}}px;
    }

    .CodeMirror-scroll {
        height: 100%;
        overflow-y: hidden;
        overflow-x: auto;
    }
    #model_showInList_form .onoffswitch.labeled .onoffswitch-inner:after {
        content: "隐藏";
    }

    #model_showInList_form .onoffswitch.labeled .onoffswitch-inner:before {
        content: "显示";
    }
</style>


<form id="model_showInList_form" method="post">
    <table width="100%" class="mdoutable">
        <tr style="font-size: 12px">
            <th width="100px">表单名称</th>
            <th width="120px">列表显示</th>
            <th width="120px">表单显示</th>
            <th width="120px">后端搜索</th>
            <th width="150px">formatter函数</th>
            <th>模型formatter函数内容</th>
        </tr>
        {{range $index, $ele := .fields}}
            {{$str1 := $ele.TableField | GetInMap $.shows}}
            <tr>
                <td style="text-align: right">{{$ele.FormName}}：</td>
                <td>
                    <div class="onoffswitch labeled greensea">
                        <input type="checkbox" name="show_{{$ele.TableField}}" class="onoffswitch-checkbox" value="" id="show_{{$ele.TableField}}" {{if eq $str1.Show true }}checked{{end}}>
                        <label class="onoffswitch-label" for="show_{{$ele.TableField}}">
                            <div class="onoffswitch-inner"></div>
                            <div class="onoffswitch-switch"></div>
                        </label>
                    </div>
                </td>

                <td>
                    <div class="onoffswitch labeled greensea">
                        <input type="checkbox" name="form_{{$ele.TableField}}" class="onoffswitch-checkbox" value="" id="form_{{$ele.TableField}}" {{if eq $str1.FormShow true }}checked{{end}}>
                        <label class="onoffswitch-label" for="form_{{$ele.TableField}}">
                            <div class="onoffswitch-inner"></div>
                            <div class="onoffswitch-switch"></div>
                        </label>
                    </div>
                </td>

                <td>
                    <select name="search_{{$ele.TableField}}" class="easyui-combobox" style="width: 120px;">
                        <option value="0" >隐藏</option>
                        <option value="1" {{if eq $str1.Search 1}}selected{{end}}>精确查询</option>
                        <option value="2" {{if eq $str1.Search 2}}selected{{end}}>模糊查询</option>
                    </select>
                </td>

                <td>
                    <label>
                        <input
                                class="easyui-textbox"
                                value="{{$str1.Formatter}}"
                                name="formatter_{{$ele.TableField}}"
                                style="width: 200px; "/>
                    </label>
                </td>
                {{if eq $index 0}}
                    <td rowspan="{{$.l}}">
                        <textarea id="formatterCodeEditor"
                                  placeholder="如: function fieldFormatter(fieldVal) { return \'fieldVal, 内部可以直接使用全局变量rowID获取每列数据的ID\'; }; fieldFormatter 就可以填写到`formatter函数名称`字段'"
                                  name="formatters" style="width:98%; height: 98%">{{$.model.Formatters}}</textarea>
                    </td>
                {{end}}
            </tr>
        {{end}}
    </table>
</form>

<script type="text/javascript">
    $(".CodeMirror").remove();
    var myCodeMirror = null;
    setTimeout(function () {
         myCodeMirror = CodeMirror.fromTextArea(document.getElementById("formatterCodeEditor"), {
            mode: "javascript",
            lineNumbers: true,
            theme: "xq-light"
        });
        myCodeMirror.refresh()
    }, 110)

    function modelFieldShowInListPageFormSubmit() {
        locker = true;
        $("#formatterCodeEditor").val(myCodeMirror.getValue());
        data = $('#model_showInList_form').serializeObject();
        for (let i in data) {
            if (i.indexOf("field_") > -1 && typeof data[i] == "string") {
                data[i] = [data[i]];
            }
        }
        $.post("/b/model/list-field-show?mid={{.mid}}", data, function (res) {
            if (res.errcode) {
                $.messager.alert('提示信息', res.errmsg, 'error');
            } else {
                $.messager.alert('提示信息', res.errmsg, 'info');
                $('#model_field_list_dialog').dialog('close');
                categoryCategoryListRefresh();
            }
        })
    }
</script>
